<template>
  <!-- 电视剧剧集 -->
  <div class="tabBox">
    <div class="tabs">
      <div class="tabPane" v-for="(item,idx) in tabs" :key="'a'+idx">
        <div class="tabsName" :class="{active:currentPage==idx+1}" @click="hanldClick(idx+1)">{{item.currName}}</div>
      </div>
    </div>
    <div class="tabsData" >
      <template v-for="(ele,index) in dataList" >
        <div class="dataItem" :key="'b'+index">
          <div v-if="index<=10">{{ele}}</div>
          <div v-if="index>10">{{ele}}</div>
        </div>
      </template>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  props: {
    total:{
      type: String|Number,
      default: ''
    }
  },
  data () {
    return {
      pageSize: 20,
      currentPage: 1,
      dataList: [],
    }
  },
  computed: {
    list(){
      let arr=[]
      for(let i=0;i<this.total;i++){
        arr.push(i+1)
      }
      return arr
    },
    totalPage(){
      return Math.ceil(this.total / this.pageSize)
    },
    tabs(){
      let data = [], arr = []
      for(let i=0;i<this.totalPage;i++){
        data = this.list.slice(((i+1) - 1) * this.pageSize, (i+1) * this.pageSize)
        arr.push({
          currName: data[0] +' - ' + data[data.length-1],
          data: data
        })
      }
      return arr
    }
  },
  watch: {},
  created () {},
  mounted () {
    this.getData();
    console.log(this.tabs);
    console.log(this.dataList);
  },
  methods: {
    // 获取tabs数据
    getData(){
      this.dataList = this.list.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize)
    },
    // 切换tabs 获取数据
    hanldClick(val){
      this.currentPage = val;
      this.getData();
    }
  },
  filters: {},
}
</script>

<style lang="less" scoped>
.tabs{
  display: flex;
  flex-direction: row;
  align-items: center;
  .tabPane{
    margin-left: 40px;
    font-size: 28px;
    width: 130px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    
    &:nth-child(1){
      margin-left: 0;
    }
    .tabsName{
      border-radius: 20px;
      background: url('../../assets/images/btn.png');
    }
    .active{
      background: url('../../assets/images/btn_active.png');
    }
  }
}
.tabsData{
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 28px;
  .dataItem{
    width: 60px;
    height: 60px;
    line-height: 60px;
    text-align: center;
    border: 1px solid #2d7ac2;
    margin: 20px 30px 5px 25px;

  }
}
</style>